package com.dhee.creditcardsystem.util;

import com.dhee.creditcardsystem.model.Users;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtilUserC {
    public static Users dml(String sql, Object... args) throws SQLException {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            conn = DBUtil.getConnection();
//            sql = "select * from users where user_Id = ?";
            pstmt = conn.prepareStatement(sql);
            for (int i = 0; i < args.length; i++) {
                pstmt.setObject(i+1, args[i]);
            }
            rs = pstmt.executeQuery();
            while (rs.next()) {
                Users users = new Users();
                users.setCstid(rs.getString("cstid"));
                users.setLoginn(rs.getString("loginn"));
                users.setDisn(rs.getString("disn"));
                users.setPass(rs.getString("pass"));
                users.setSer(rs.getString("ser"));
                users.setToken(rs.getString("token"));
                users.setKbn(rs.getString("kbn"));
                users.setMail(rs.getString("mail"));
                users.setInsertdte(rs.getString("insertdte"));
                users.setInsertid(rs.getString("insertid"));
                users.setUpdatedte(rs.getString("updatedte"));
                users.setUpdateid(rs.getString("updateid"));
                users.setDeleteflg(rs.getString("deleteflg"));
                users.setDeletedte(rs.getString("deletedte"));
                return users;
            }

        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.close(conn, pstmt, rs);
        }

        return null;
    }
}
